package com.kly.user.controller;

import cn.hutool.json.JSONUtil;
import com.fqgj.common.api.Page;
import com.fqgj.common.api.Response;
import com.kly.user.dto.UserAccountDto;
import com.kly.user.dto.UserBaseDto;
import com.kly.user.dto.UserChangeDto;
import com.kly.user.dto.UserInfoDto;
import com.kly.user.dto.WlmUserDto;
import com.kly.user.enums.OnlineStatus;
import com.kly.user.service.UserService;
import com.kly.user.service.WlmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * 测试接口
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private WlmService wlmService;

    @ResponseBody
    @RequestMapping(value = "/changeUser")
    public Response<UserInfoDto> changeUserInfo(@RequestBody UserChangeDto userChange, BindingResult results,
                                                @RequestParam String userCode) {
        return userService.changeUserInfo(userChange, userCode);
    }

    @ResponseBody
    @RequestMapping(value = "/initUserInfo")
    public Response<UserInfoDto> initUserInfo(@Valid @RequestBody UserChangeDto userChange, BindingResult results,
                                              @RequestParam String userCode) {
        if (results.hasErrors()) {
            System.out.println("出现问题：" + results.getFieldErrors().get(0));
            return Response.error();
        }

        return Response.ok();
    }

    @ResponseBody
    @RequestMapping(value = "/initUserInfo2")
    public Response<UserInfoDto> initUserInfo2(@Valid @RequestBody UserChangeDto userChange, BindingResult results,
                                               @RequestParam String userCode) {
        if (results.hasErrors()) {
            System.out.println("出现问题：" + results.getFieldErrors().get(0));
        }
        return Response.ok();
    }

    @ResponseBody
    @RequestMapping(value = "/userInfo")
    public Response<UserInfoDto> getUserByUserCode(String userCode) {
        return userService.getUserByUserCode(userCode);
    }

    @ResponseBody
    @RequestMapping(value = "/userBase")
    public Response<UserBaseDto> getUserBaseInfo(String userCode) {
        return userService.getUserBaseInfo(userCode);
    }


    @ResponseBody
    @RequestMapping(value = "/userAccount")
    public Response<UserAccountDto> getUserAccount(String userCode) {
        return userService.getUserAccount(userCode);
    }

    @ResponseBody
    @RequestMapping(value = "/accountBind")
    public void accountBind(@RequestBody UserAccountDto userAccountDto, @RequestParam String userCode) {
        userService.accountBind(userAccountDto, userCode);

    }

    @ResponseBody
    @RequestMapping(value = "/removeAccount")
    public void removeAccount(String userCode, Integer accountType) {
        userService.removeAccount(userCode, accountType);
    }

    @ResponseBody
    @RequestMapping(value = "/removeUser")
    public void removeUser(String userCode) {
        userService.removeUser(userCode);
    }

    @ResponseBody
    @RequestMapping(value = "/test01")
    public void test01(String userCode){
        Integer integer = userService.updateOnline(userCode);
        System.out.println(integer);
    }

//    @ResponseBody
//    @RequestMapping(value = "/test02")
//    public void test01(@RequestBody Set<String> userCodeSet){
//        Integer integer = userService.offlineByUserCodeList(userCodeSet, OnlineStatus.ONLINE_STATUS);
//        System.out.println(integer);
//    }

    @ResponseBody
    @RequestMapping(value = "/test03")
    public void test03(String userCode){
        Response<List<WlmUserDto>> listResponse = wlmService.queryLikeEachOtherList(userCode, new Page(10, 1));
        System.out.println(JSONUtil.toJsonStr(listResponse));
    }

    @ResponseBody
    @RequestMapping(value = "/test05")
    public void test05(){
        userService.getUsers("303709715312040170");
        System.out.println(JSONUtil.toJsonStr(""));
    }

    @ResponseBody
    @RequestMapping(value = "/test06")
    public void test06(){
        wlmService.recommendUsers("881150776146268160",30);
        System.out.println(JSONUtil.toJsonStr(""));
    }



    @ResponseBody
    @RequestMapping(value = "/test07")
    public void test07(){
        userService.canConnect("1748179920197091328");
        System.out.println(JSONUtil.toJsonStr(""));
    }


}
